home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
-
- Program name: Structure Content Drawer demo program.
-
- Author: Gareth Williams
-
- Description: Demonstrates the structure content drawer module.
-
- Modification history : (Version), (Date), (Name), (Description).
-
- 1.0, 1st July 1991, G. Williams, First Version.
-
- 2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
-
- SunOS requirements: SunPHIGS 2.0, OpenWindows 3.0.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <math.h>
- #include <phigs.h>
- #include "ptk.h"
-
- #define WS1 1
-
- /* Operating system dependent code, UNIX/VMS pathnames */
- /* UNIX pathnames */
- #define SCRIPTNAME "../scripts/postcard.scr"
- #define OPENWSNAME "../scripts/openws.scr"
-
- /*
- #ifdef VMS
- #define SCRIPTNAME "[-.scripts]postcard.scr"
- #endif
- */
-
- static char *colwrd[] =
- {
- "BLACK", "WHITE", "GREEN",
- "BLUE", "CYAN", "GREY", "RED"
- };
-
- static Pfloat devx, devy, devz;
- static Pint textfont, white, black, green, grey, blue;
- static ptkboolean docolour = FALSE;
-
- /*--------------------------------------------------------------------------*/
-
- static void set_attrs()
- {
- if (docolour)
- {
- pset_text_colr_ind(black);
- pset_edge_flag(PEDGE_ON);
- pset_int_style(PSTYLE_SOLID);
- pset_edge_colr_ind(white);
- pset_int_colr_ind(green);
- }
- } /* set_attrs */
-
- /*--------------------------------------------------------------------------*/
-
- static void options(C(void))
- {
- char commandstr[20], writestr[50];
- Pint lencom, lenstr, err, elem1, elem2, eptr, postcardid;
- ptkboolean structquit;
- Plimit echoarea;
-
- structquit = FALSE;
- eptr = 0;
- postcardid = ptk_stringtoint("structureid", "postcard");
- do
- {
- echoarea = ptk_limit(0.0, devx, 0.0, devy * 0.1);
- ptk_readstring(WS1, "range", "Input command (default = range) >",
- &echoarea, 20, commandstr, &lencom);
- if (strncmp(commandstr, "range", lencom) == 0)
- {
- elem1 = ptk_readint(WS1, 1, "Input element number (1) >", &echoarea);
- elem2 = ptk_readint(WS1, 0, "Input element number (0) >", &echoarea);
- pempty_struct(ptk_stringtoint("structureid", "content"));
- popen_struct(ptk_stringtoint("structureid", "content"));
- set_attrs();
- ptk_structcontent(WS1, postcardid, elem1, elem2, eptr, textfont, &err);
- pclose_struct();
- }
- else
- if (strncmp(commandstr, "pointer", lencom) == 0)
- {
- eptr = ptk_readint(WS1, 0, "Input element pointer (0) >", &echoarea);
- popen_struct(ptk_stringtoint("structureid", "content"));
- ptk_setstructcontentelemptr(ptk_stringtoint("structureid", "content"),
- eptr);
- pclose_struct();
- }
- else if (strncmp(commandstr, "hardcopy", lencom) == 0)
- {
- Pint stid, lenname;
- char filename[80];
-
- ptk_readstring(WS1, "content",
- "Input filename (default = content) >", &echoarea,
- 80, filename, &lenname);
-
- /* Implementation dependent code, open a hardcopy workstation */
- #ifdef SUN
- popen_ws(2, filename, phigs_ws_type_cgm_out);
- ppost_struct(2, ptk_stringtoint("structureid", "content"), 0.0);
- pupd_ws(2, PFLAG_PERFORM);
- pclose_ws(2);
- #endif
- }
- else if (strncmp(commandstr, "help", lencom) == 0)
- {
- printf("stcttest options\n");
- printf("----------------\n");
- printf("range - define element range for structure content diagram\n");
- printf("pointer - set element pointer\n");
- printf("hardcopy - post structure content to hardcopy workstation\n");
- printf("quit - exit stcttest\n");
- }
- else if (strncmp(commandstr, "quit", lencom) == 0)
- {
- structquit = TRUE;
- }
- else
- {
- printf("Command unknown\n");
- }
- pupd_ws(WS1, PFLAG_PERFORM);
- } while (structquit == FALSE);
- }
-
- /*--------------------------------------------------------------------------*/
-
- main()
- {
- FILE *f;
- char dummystr[10];
- Pint dummylen, err, minid, maxid;
- Pint wst;
-
- printf("Demonstrating the structure draw module of the PHIGS Toolkit...\n");
-
- /* Implementation dependent code, open PHIGS and workstation */
- #ifdef SUN
- printf("Opening SunPHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
-
- /* create the workstation type (either tool or canvas)
-
- wst = phigs_ws_type_create( phigs_ws_type_x_tool,
- PHIGS_TOOL_LABEL, "SunPHIGS Tool Workstation",
- 0);
- if ( !wst )
- {
- pclose_phigs();
- exit(1);
- }
-
- popen_ws(WS1, (void *)NULL, wst);
- {
- Pws_st ws_state;
-
- pinq_ws_st(&ws_state);
- if (ws_state != PWS_ST_WSOP)
- exit(3);
- }
- */
- #endif
- #ifdef PEXSI
- printf("Opening PEX-SI PHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
- #ifdef HP
- printf("Opening HP PHIGS...\n");
- popen_phigs(stderr, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
-
- ptk_inqmaxdevicecoords(WS1, &devx, &devy);
- devz = 0.0;
-
- #ifdef SUN
- #ifndef SUNMONO
- docolour = TRUE;
- #endif
- #endif
- #ifdef HP
- #ifndef HPMONO
- docolour = TRUE;
- #endif
- #endif
- #ifdef PEXSI
- #ifndef PEXSIMONO
- docolour = TRUE;
- #endif
- #endif
-
- pset_disp_upd_st(WS1, PDEFER_WAIT, PMODE_NIVE);
- minid = 1;
- maxid = 30;
- ptk_inithashtables();
- ptk_createhashtable("structureid", minid, maxid);
- ptk_createhashtable("label", 0, maxid);
- ptk_createhashtable("colourindex", 1, 8);
-
- /* set colours */
- if (docolour)
- {
- ptk_setupcolourtable(WS1, 7, colwrd);
- green = ptk_stringtoint("colourindex", "green");
- grey = ptk_stringtoint("colourindex", "grey");
- white = ptk_stringtoint("colourindex", "white");
- black = ptk_stringtoint("colourindex", "black");
- blue = ptk_stringtoint("colourindex", "blue");
-
- /* Implementation dependent code, choose a nice font */
- #ifdef SUN
- textfont = PFONT_TRIPLEX;
- #endif
- #ifndef SUN
- textfont = 1;
- #endif
- ptk_setbackgroundcolourind(WS1, grey);
- }
-
- if (ptk_readphinterscript(SCRIPTNAME, NULL, NULL))
- {
- popen_struct(ptk_stringtoint("structureid", "content"));
- set_attrs();
- ptk_structcontent(WS1, ptk_stringtoint("structureid", "postcard"),
- 1, 0, 0, textfont, &err);
- pclose_struct();
-
- if (err == 0)
- ppost_struct(WS1, ptk_stringtoint("structureid", "content"), 0.0);
-
- pupd_ws(WS1, PFLAG_PERFORM);
- options();
- }
-
- pclose_ws(1);
- pclose_phigs();
- exit(0);
- }
-
- /*--------------------------------------------------------------------------*/
-
- /* end of stcttest.c */
-